{include file="../application/admin/view/common/header.html" /}
<style type="text/css">
    .btn-blue, .btn-blue:hover, .btn-blue:focus {
        background-color: #3171b4;
        border-color: #3171b4;
        color: #ffffff;
    }

    .table-btn, .table-btn:hover, .table-btn:focus {
        border-radius: 2px;
        -webkit-border-radius: 2px;
        text-transform: capitalize;
        font-size: 13px;
        padding: 0px 4px;
        font-weight: 400;
        color: #666666;
        background-color: #c3c3c3;
    }

    .enable {
        color: #3171b4
    }

    .disable {
        color: #ff2929
    }

    .table {
        text-align: center;
    }

    .table tbody {
        font-size: 13px;
        color: #333333;
    }

    .table tbody .buttons {
        padding: 3px;
    }

    .table thead {
        background-color: #aad4ff;
    }

    .table thead {
        font-size: 14px;
        font-weight: bold;
        color: #111111;
    }

    .table thead th {
        text-align: center;
    }

    .system-nav a {
        font-size: 14px;
        color: #111111;
    }

    .system-nav a i {
        display: inline-block;
        vertical-align: middle;
        margin-top: -2px;
        width: 15px;
    }

    .system-nav .nav-second-level li a, .system-nav .nav-third-level li a {
        color: #111111;
    }

    .system-nav .nav-second-level li a:hover, .system-nav .nav-thrid-level li a:hover {
        color: #1bb11b;
    }

    .system-box {
        border: 1px solid #e1e8ed;
        padding-left: 0px;
        padding-right: 0px;
    }

    .system-box .system-nav {
        height: 400px;
        overflow-y: scroll;
    }

    .system-nav li .choose, .system-nav .nav-second-level li .choose, .system-nav .nav-third-level li .choose {
        color: #1bb11b;
    }

    .system-nav li .checked {
        color: #3171b4;
    }

    .system-nav li .bt-col, .system-nav .nav-second-level li .bt-col, .system-nav .nav-third-level li .bt-col {
        color: #999999;
    }

    .system-p-title {
        text-indent: 15px;
        color: #3171b4;
        font-weight: bold;
    }

    .system-p-title span {
        font-size: 14px;
    }

    .system-nav .buttons .btn {
        padding: 2px 0px;
        border: none;
        background-color: #eee;
        margin-right: 8px;
        font-size: 16px;
    }

    .system-nav .buttons .btn:hover {
        background-color: #eee;
    }
</style>

<!--main content start-->
<section class="main-content">


    <!--start page content-->

    <div class="row">

        <div class="col-md-12">
            <div class="panel panel-default collapsed">
                <div class="panel-heading">
                    <a class="btn btn-danger ui-w" onclick="datadel()" href="javascript:void(0);"><span
                            class="ui-icon ui-icon-trash"></span>批量删除</a>
                    <a class="btn btn-blue ui-w" onclick="system_add(this)" href="javascript:void(0);"><span
                            class="ui-icon ui-icon-plus"></span>添加模块</a>
                    <label for="name"
                           style="color: #666666;font-size: 16px;font-weight: normal;line-height: 34px;margin: 3px 0;margin-left: 25px;">模块名称
                        <select class="system-role" style="height: 34px;border:1px solid #e0e0e0;width: 150px; ">
                        </select>
                    </label>
                    <div class="search-form">
                        <input type="text" id="select1" class="form-control" placeholder="搜索名称"/>
                        <button id="select2" type="button" class="btn-search"><i class="fa fa-search"></i></button>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="col-lg-5 col-md-5 col-xs-5 system-box" style="">
                        <div class="system-list-box">
                            <!-- <ul class="nav system-nav" id="system-list">
                                    <li class="nav-heading"><span>地区</span></li>
                                   <li class="active">
                                       <a href="#" class="bt-col" aria-expanded="true" statu="2"><i class="icon-list"></i>湖北省
                                        <div class="buttons" style="float: right;">
                                          <button type="button" class="btn btn-default"><i class="fa fa-check-circle-o enable"></i>激活</button>
                                          <button type="button" class="btn btn-default" onclick="system_add2(this)"><i class="fa fa-plus"></i>添加</button>
                                              <button type="button" class="btn btn-default" onclick="system_edit(this)"><i class="fa fa-pencil"></i>编辑</button>
                                              <button type="button" class="btn btn-default" onclick="system_del_main(this)"><i class="fa fa-trash-o"></i>删除</button>
                                        </div>
                                       </a>
                                       <ul class="nav-second-level nav in" aria-expanded="true">
                                           <li><a href="#" class="choose checked" statu="1"><i class="icon-list"></i>武汉市
                                            <div class="buttons" style="float: right;">
                                              <button type="button" class="btn btn-default"><i class="fa fa-ban"></i>禁用</button>
                                              <button type="button" class="btn btn-default" onclick="system_add2(this)"><i class="fa fa-plus"></i>添加</button>
                                              <button type="button" class="btn btn-default" onclick="system_edit(this)"><i class="fa fa-pencil"></i>编辑</button>
                                              <button type="button" class="btn btn-default" onclick="system_del_main(this)"><i class="fa fa-trash-o"></i>删除</button>
                                            </div>
                                           </a></li>
                                           <li><a href="#"><i class="icon-list"></i>宜昌市</a></li>
                                       </ul>
                                   </li>
                                   <li>
                                       <a href="#"><i class="icon-list"></i>湖北省</a>
                                       <ul class="nav-second-level nav collapse" aria-expanded="false">
                                           <li><a href="#"><i class="icon-list"></i>武汉市</a></li>
                                           <li><a href="#"><i class="icon-list"></i>宜昌市</a></li>
                                       </ul>
                                   </li>
                                   <li>
                                       <a href="#"><i class="icon-list"></i>湖北省</a>
                                       <ul class="nav-second-level nav collapse" aria-expanded="false">
                                           <li><a href="#"><i class="icon-list"></i>武汉市</a></li>
                                           <li><a href="#"><i class="icon-list"></i>宜昌市</a></li>
                                       </ul>
                                   </li>
                                   <li>
                                       <a href="#"><i class="icon-list"></i>湖北省</a>
                                       <ul class="nav-second-level nav collapse" aria-expanded="false">
                                           <li><a href="#"><i class="icon-list"></i>武汉市</a></li>
                                           <li><a href="#"><i class="icon-list"></i>宜昌市</a></li>
                                       </ul>
                                   </li>
                                   <li>
                                       <a href="#"><i class="icon-list"></i>湖北省</a>
                                       <ul class="nav-second-level nav collapse" aria-expanded="false">
                                           <li><a href="#"><i class="icon-list"></i>武汉市</a></li>
                                           <li><a href="#"><i class="icon-list"></i>宜昌市</a></li>
                                       </ul>
                                   </li>
                                   <li>
                                       <a href="#"><i class="icon-list"></i>湖北省</a>
                                       <ul class="nav-second-level nav collapse" aria-expanded="false">
                                           <li><a href="#"><i class="icon-list"></i>武汉市</a></li>
                                           <li><a href="#"><i class="icon-list"></i>宜昌市</a></li>
                                       </ul>
                                   </li>
                                   <li>
                                       <a href="#"><i class="icon-list"></i>湖北省</a>
                                       <ul class="nav-second-level nav collapse" aria-expanded="false">
                                           <li><a href="#"><i class="icon-list"></i>武汉市</a></li>
                                           <li><a href="#"><i class="icon-list"></i>宜昌市</a></li>
                                       </ul>
                                   </li>
                                   <li>
                                       <a href="#"><i class="icon-list"></i>湖北省</a>
                                       <ul class="nav-second-level nav collapse" aria-expanded="false">
                                           <li><a href="#"><i class="icon-list"></i>武汉市1</a>
                                               <ul class="nav-third-level nav collapse" aria-expanded="true">
                                                   <li><a href="#">武昌区</a></li>
                                                   <li><a href="#">汉阳区</a></li>
                                               </ul>
                                           </li>
                                           <li><a href="#">宜昌市</a></li>
                                       </ul>
                                    </li>
                                  </ul> -->

                        </div>
                    </div>
                    <div class="col-lg-7 col-md-7 col-xs-7" style="padding-left: 0;">
                        <p class="system-p-title">湖北省/<span>武汉市</span></p>
                        <table class="table table-hover table-striped table-bordered" data-page-size="12"
                               data-filter=#filter>
                            <thead>
                            <tr>
                                <th>选择</th>
                                <th>序号</th>
                                <th>名称</th>
                                <th>所属模块</th>
                                <th>创建时间</th>
                                <th>是否激活</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <!-- <tr>
                                <td><input type="checkbox" name=""></td>
                                <td>01</td>
                                <td>洪山区</td>
                                <td>地区管理</td>
                                <td>2017-12-08 15：32：32</td>
                                <td class="td-status disable">未激活</td>
                                <td class="buttons td-manage">
                                    <a class="btn table-btn" onclick="system_start(this)" href="#"><i class="fa fa-check-circle-o enable" title="激活"></i></a>
                                    <a class="btn table-btn" onclick="system_edit(this)" href="#" title="编辑"><i class="fa fa-pencil"></i></a>
                                    <a class="btn table-btn" onclick="system_del(this,'1')" href="#" title="删除"><i class="fa fa-trash-o"></i></a>
                                </td>
                            </tr>
                            <tr>
                                <td><input type="checkbox" name=""></td>
                                <td>02</td>
                                <td>洪山区</td>
                                <td>地区管理</td>
                                <td>2017-12-08 15：32：32</td>
                                <td class="td-status enable">已激活</td>
                                <td class="buttons td-manage">
                                    <a class="btn table-btn " onclick="system_stop(this)" href="javascript:;" title="禁用"><i class="fa fa-ban"></i></a>
                                    <a class="btn table-btn" onclick="system_edit(this)" href="#" title="编辑"><i class="fa fa-pencil"></i></a>
                                    <a class="btn table-btn" onclick="syetem_del(this)" href="#" title="删除"><i class="fa fa-trash-o"></i></a>
                                </td>
                            </tr> -->

                            </tbody>
                        </table>
                        <div class="pager" id="page" style="text-align: right;"></div>
                    </div>
                </div>
            </div>
        </div>
    </div><!--end row-->

    <!--end page content-->


</section>
<!--end main content-->


<!--Common plugins-->
<script src="_JS_/bootstrap.min.js"></script>
<script src="_JS_/jquery.base64.js"></script>
<script src="_JS_/jquery.cookie.js"></script>
<script src="_JS_/jasny-bootstrap.min.js"></script>
<script src="_JS_/jquery.slimscroll.min.js"></script>
<script src="_JS_/jquery.nanoscroller.min.js"></script>
<script src="_JS_/metismenu.min.js"></script>
<script src="_JS_/float-custom.js"></script>
<script type="text/javascript" src="_JS_/layer/layer.js"></script>
<script type="text/javascript" src="_JS_/laypage/laypage.js"></script>
<script type="text/javascript" src="_JS_/getMyDate.js"></script>
<script>
    $(function () {
        $("#page-title").html("数据字典");
        //模块列表
        $.ajax({
            type: "get",
            url: "{:url('api/Dictionary/model')}",
            dataType: 'jsonp',
            jsonp: 'callback',
            beforeSend: function () {
                var index = layer.load(1, {
                    shade: [0.1, '#333333'] //0.1透明度的白色背景
                });
            },
            success: function (msg) {
                if (msg.code == 200) {
                    for (var i = 0; i < msg.data.length; i++) {
                        var html = '<option value="' + msg.data[i].tid + '">' + msg.data[i].name + '</option>';
                        $(".system-role").append(html);
                    }
                }
                var system_tid = $('.system-role').val();
                system_list_l(system_tid);

                if (msg.code == 1000) {
                    layer.msg('加载失败!', {icon: 1, time: 1000});
                }
            }
        })
        //切换模块
        $('.system-role').change(function () {
            var system_id = $('.system-role').val();
            system_list_l(system_id);
        })

        //获取左侧列表
        function system_list_l(system_tid) {
            var name = $("#select1").val();
            $.ajax({
                type: "get",
                url: "{:url('api/Dictionary/index')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'tid': system_tid},
                beforeSend: function () {
                    var index = layer.load(1, {
                        shade: [0.1, '#333333'] //0.1透明度的白色背景
                    });
                },
                success: function (msg) {
                    layer.closeAll();
                    if (msg.code == 200) {
                        $("#system_management").addClass("active").children("ul").addClass("in");
                        $("#dictionary").addClass("choose");
                        $(".system-list-box").html("");
                        if (msg.data.length != 0) {


                            //头部
                            thtml = '<ul class="nav system-nav" id="system-list"><li class="nav-heading system-li" id="' + msg.data[0].id + '" pid="' + msg.data[0].pid + '" tag="' + msg.data[0].tag + '">';
                            if (msg.data[0].status == 1) {
                                thtml += '<a href="#" status="' + msg.data[0].status + '"><span>' + msg.data[0].name + '</span>';
                            } else if (msg.data[0].status == 2) {
                                thtml += '<a href="#" class="bt-col" status="' + msg.data[0].status + '"><span>' + msg.data[0].name + '</span>';
                            }
                            thtml += '<div class="buttons hide" style="float: right;">';
                            if (msg.data[0].status == 1) {
                                thtml += '<button type="button" class="btn btn-default"  onclick="system_stop_l(this)" title="禁用"><i class="fa fa-ban" ></i></button>'
                            } else if (msg.data[0].status == 2) {
                                thtml += '<button type="button" class="btn btn-default" onclick="system_start_l(this)" title="激活"><i class="fa fa-check-circle-o enable"></i></button>';
                            }
                            thtml += '<button type="button" class="btn btn-default" onclick="system_add2(this,' + msg.data[0].id + ',\'0\')" title="添加"><i class="fa fa-plus"></i></button>';
                            thtml += '<button type="button" class="btn btn-default" onclick="system_edit(this,' + msg.data[0].id + ')" title="编辑"><i class="fa fa-pencil"></i></button>';
                            thtml += '<button type="button" class="btn btn-default" onclick="system_del_main(this)" title="删除"><i class="fa fa-trash-o"></i></button>';
                            thtml += '</div></a></li></ul>';
                            $(".system-list-box").append(thtml);

                            //列表
                            if (msg.data[0].son != null) {
                                var lgh = msg.data[0].son.length;
                                for (var i = 0; i < lgh; i++) {
                                    var mhtml = '<li class="system-li" num="' + i + '" id="' + msg.data[0].son[i].id + '" pid="' + msg.data[0].son[i].pid + '" tag="' + msg.data[0].son[i].tag + '">';
                                    if (msg.data[0].son[i].status == 1) {
                                        mhtml += '<a href="#" aria-expanded="false" status="' + msg.data[0].son[i].status + '">';
                                    } else if (msg.data[0].son[i].status == 2) {
                                        mhtml += '<a href="#" class="bt-col" aria-expanded="false" status="' + msg.data[0].son[i].status + '">';
                                    }
                                    mhtml += '<i class="icon-list"></i>' + msg.data[0].son[i].name + '';
                                    mhtml += '<div class="buttons hide" style="float: right;">';
                                    //判断激活状态
                                    if (msg.data[0].son[i].status == 1) {
                                        mhtml += '<button type="button" class="btn btn-default"  onclick="system_stop_l(this)" title="禁用"><i class="fa fa-ban" ></i></button>'
                                    } else if (msg.data[0].son[i].status == 2) {
                                        mhtml += '<button type="button" class="btn btn-default" onclick="system_start_l(this)" title="激活"><i class="fa fa-check-circle-o enable"></i></button>';
                                    }
                                    mhtml += '<button type="button" class="btn btn-default" onclick="system_add2(this,' + msg.data[0].son[i].id + ',\'0\')" title="添加"><i class="fa fa-plus"></i></button>';
                                    mhtml += '<button type="button" class="btn btn-default" onclick="system_edit(this,' + msg.data[0].son[i].id + ')" title="编辑"><i class="fa fa-pencil"></i></button>';
                                    mhtml += '<button type="button" class="btn btn-default" onclick="system_del_main(this)" title="删除"><i class="fa fa-trash-o"></i></button>';
                                    mhtml += '</div></a></li>';
                                    $(".system-nav").append(mhtml);
                                    $('.system-nav li[num="0"]').addClass("active");
                                    $('.system-nav li[num="0"] a').attr('aria-expanded', 'true');
                                    $('.system-nav li[num="0"] ul').addClass("in").attr('aria-expanded', 'true');


                                    //是否有子集
                                    if (msg.data[0].son[i].son != null) {
                                        $('.system-nav li[num="' + i + '"]').append('<ul class="nav-second-level nav collapse" aria-expanded="false"></ul>')
                                        for (var j = 0; j < msg.data[0].son[i].son.length; j++) {
                                            var lhtml = '<li id="' + msg.data[0].son[i].son[j].id + '" pid="' + msg.data[0].son[i].son[j].pid + '" tag="' + msg.data[0].son[i].son[j].tag + '">';
                                            if (msg.data[0].son[i].son[j].status == 1) {
                                                lhtml += '<a href="#" class="" status="' + msg.data[0].son[i].son[j].status + '">';
                                            } else if (msg.data[0].son[i].son[j].status == 2) {
                                                lhtml += '<a href="#" class="bt-col" status="' + msg.data[0].son[i].son[j].status + '">';
                                            }
                                            lhtml += '<i class="icon-list"></i>' + msg.data[0].son[i].son[j].name + '';
                                            lhtml += '<div class="buttons hide" style="float: right;">';
                                            //判断激活状态
                                            if (msg.data[0].son[i].son[j].status == 1) {
                                                lhtml += '<button type="button" class="btn btn-default" title="禁用"><i class="fa fa-ban" onclick="system_stop_l(this)"></i></button>'
                                            } else if (msg.data[0].son[i].son[j].status == 2) {
                                                lhtml += '<button type="button" class="btn btn-default" onclick="system_start_l(this)" title="激活"><i class="fa fa-check-circle-o enable"></i></button>';
                                            }
                                            lhtml += '<button type="button" class="btn btn-default" onclick="system_add2(this,' + msg.data[0].son[i].son[j].id + ',\'1\')" title="添加"><i class="fa fa-plus"></i></button>';
                                            lhtml += '<button type="button" class="btn btn-default" onclick="system_edit(this,' + msg.data[0].son[i].son[j].id + ')" title="编辑"><i class="fa fa-pencil"></i></button>';
                                            lhtml += '<button type="button" class="btn btn-default" onclick="system_del_main(this)" title="删除"><i class="fa fa-trash-o"></i></button>';
                                            lhtml += '</div></a></li>';
                                            $('.system-nav li[num="' + i + '"] ul').append(lhtml);

                                        }
                                    }

                                }
                            }

                        }

                        //选择一级子类
                        $(".system-nav li a").on("click", function () {
                            $(".system-nav li a").removeClass("checked");
                            $(this).addClass("checked");
                        })

                        //选中二级子类
                        $(".nav-second-level li a").on("click", function () {
                            $(".system-nav li a").removeClass("choose");
                            $(this).addClass("choose");
                            if ($(this).attr('statu') == '1') {
                                $(this).removeClass("bt-col").addClass("bt-col");
                            }
                            var id = $(this).parent('li').attr('id');
                            //sye_name1=
                            system_list(id, 1);

                        });

                        //hover显示操作按钮
                        $(".system-nav li a").hover(function () {
                                $(this).find('.buttons').removeClass('hide');
                            },
                            function () {
                                $(this).find('.buttons').addClass('hide');
                            }
                        );

                        $("#system-list").metisMenu();
                    }

                    if (msg.code == 1000) {
                        layer.msg('加载失败!', {icon: 1, time: 1000});
                    }
                }
            });
        }

        // $("#select2").click(function () {
        //     system_list_l();
        // })
        //
        // //回车键绑定搜索
        // $(".search-form").keydown(function (event) {
        //     if (event.keyCode == 13) {
        //         system_list_l();
        //     }
        // });


        //右侧列表
        function system_list(id, page) {
            // var name = $("#select1").val();
            $.ajax({
                type: "get",
                url: "{:url('api/Dictionary/d_list')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'id': id},
                beforeSend: function () {
                    var index = layer.load(1, {
                        shade: [0.1, '#333333'] //0.1透明度的白色背景
                    });
                },
                success: function (msg) {
                    layer.closeAll();
                    if (msg.code == 200) {
                        $(".table tbody").html("");
                        var pages = Math.ceil(msg.data.count / 10);
                        if (msg.data.res.length > 0) {
                            for (var i = 0; i < msg.data.res.length; i++) {
                                var time = msg.data.res[i].time;
                                ltime = getMyDate(time * 1000);
                                var html = '<tr id="' + msg.data.res[i].id + '" pid="' + msg.data.res[i].pid + '"><td><input type="checkbox" name="allcheck"></td>';
                                html += '<td>' + msg.data.res[i].id + '</td><td>' + msg.data.res[i].name + '</td><td class="sys-name" name="' + msg.data.res[i].name.t_name + '">' + msg.data.res[i].t_name + '</td><td>' + ltime + '</td>';
                                if (msg.data.res[i].status == 1) {
                                    html += '<td class="td-status enable">已激活</td><td class="buttons td-manage"><a class="btn table-btn " onclick="system_stop(this)" href="javascript:;" title="禁用"><i class="fa fa-ban"></i></a>';
                                } else if (msg.data.res[i].status == 2) {
                                    html += '<td class="td-status disable">未激活</td><td class="buttons td-manage"><a class="btn table-btn" onclick="system_start(this)" href="#"><i class="fa fa-check-circle-o enable" title="激活"></i></a>';
                                }
                                html += '<a class="btn table-btn" onclick="system_edit(this,' + msg.data.res[i].id + ')" href="#" title="编辑"><i class="fa fa-pencil"></i></a><a class="btn table-btn" onclick="syetem_del(this)" href="#" title="删除"><i class="fa fa-trash-o"></i></a>';
                                html += '</td></tr>';
                                $(".table tbody").append(html);//table添加数据
                                $(".table").attr("pages", page);
                                //分页
                                laypage({
                                    cont: 'page',
                                    pages: pages,
                                    curr: page,
                                    jump: function (obj, first) {
                                        if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                            system_list(id, obj.curr);
                                        }
                                    }
                                });
                            }
                        }
                    }

                }
            });
        }

    })


    /*批量删除*/
    function datadel(obj) {
        var arrs = new Array();
        $(".table input[name='allcheck']:checked").each(function () {
            arrs.push($(this).parents('tr').attr('id'));
        });
        if (arrs.length == 0) {
            layer.msg('请选择删除项!', {icon: 2, time: 1000});
            return;
        }
        var ids = arrs.join(",");
        layer.confirm('确认要删除多个吗？', function (index) {
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: "get",
                url: "{:url('api/Dictionary/batch_del')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'id': ids},
                success: function (msg) {
                    if (msg.code == 200) {
                        $(".table input[name='allcheck']:checked").parents('tr').remove();
                        layer.msg('已删除!', {icon: 1, time: 1000});
                    }
                    if (msg.code == 1000) {
                        layer.msg('删除失败!', {icon: 5, time: 1000});
                    }
                }
            });
            /*$(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});*/
        });
    }

    /*添加*/
    function system_add(obj) {
        layer.open({
            type: 2,
            title: '模块',
            shadeClose: true,
            shade: 0.8,
            area: ['500px', '400px'],
            content: "{:url('Dictionary/add')}"
        });
    }


    function system_add2(obj, id, tag) {
        layer.open({
            type: 2,
            title: '添加子集',
            shadeClose: true,
            shade: 0.8,
            area: ['500px', '400px'],
            content: "{:url('Dictionary/system_add2')}" + "?id=" + id + "&tag=" + tag,
        });
        event.stopPropagation();    //  阻止事件冒泡
    }

    /* 编辑*/
    function system_edit(obj, id) {
        layer.open({
            type: 2,
            title: '编辑',
            shadeClose: true,
            shade: 0.8,
            area: ['500px', '400px'],
            content: "{:url('Dictionary/edit')}" + "?id=" + id,
        });
        event.stopPropagation();    //  阻止事件冒泡
    }

    //大类删除
    function system_del_main(obj) {
        event.stopPropagation();    //  阻止事件冒泡
        layer.confirm('确认要删除吗？', function (index) {
            //此处请求后台程序，下方是成功后的前台处理……
            var id = $(obj).parents("li").attr("id");
            tag = $(obj).parents("li").attr('tag');
            $.ajax({
                type: "get",
                url: "{:url('api/Dictionary/batch_del')}",
                dataType: "jsonp",
                jsonp: "callback",
                data: {'id': id},
                success: function (msg) {
                    if (msg.code == 200) {
                        if (tag == 0) {
                            window.location.reload();
                        } else {
                            $('#' + id).remove();
                        }
                        // system_list(pid,pages_num);
                        layer.msg('已删除!', {icon: 1, time: 1000});
                    } else {
                        layer.msg('删除失败!', {icon: 2, time: 1000});
                    }
                },
            });
        });
    }


    /*左侧禁用*/
    function system_stop_l(obj) {
        event.stopPropagation();    //  阻止事件冒泡
        layer.confirm('确认要禁用吗？', function (index) {
            var status = 2;
            id = $(obj).parents("li").attr("id");
            $.ajax({
                type: "get",
                url: "{:url('api/Dictionary/change')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'id': id, 'status': status},
                success: function (msg) {
                    if (msg.code == 200) {
                        $(obj).parent(".buttons").prepend('<button type="button" class="btn btn-default" onclick="system_start_l(this)" title="激活"><i class="fa fa-check-circle-o enable"></i></button>');
                        $(obj).parents('a').attr("status", "2").addClass('bt-col');
                        $(obj).remove();
                        layer.msg('已禁用!', {icon: 1, time: 1000});
                    }
                    if (msg.code == 1000) {
                        layer.msg('禁用失败!', {icon: 1, time: 1000});
                    }
                }
            });
        });
    }

    //左边栏激活
    function system_start_l(obj) {
        event.stopPropagation();    //  阻止事件冒泡
        layer.confirm('确认要激活吗？', function (index) {
            var status = 1;
            id = $(obj).parents("li").attr("id");
            $.ajax({
                type: "get",
                url: "{:url('api/Dictionary/change')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'id': id, 'status': status},
                success: function (msg) {
                    if (msg.code == 200) {
                        $(obj).parent(".buttons").prepend('<button type="button" class="btn btn-default" onclick="system_stop_l(this)" title="禁用"><i class="fa fa-ban"></i></button>');
                        $(obj).parents('a').attr("status", "1").removeClass('bt-col');
                        $(obj).remove();
                        layer.msg('已激活!', {icon: 1, time: 1000});
                    }
                    if (msg.code == 1000) {
                        layer.msg('禁用失败!', {icon: 1, time: 1000});
                    }
                }
            });
        });
    }


    /*右侧列表激活*/
    function system_start(obj) {

        layer.confirm('确认要激活吗？', function (index) {
            var status = 1;
            id = $(obj).parents("tr").attr("id");
            $.ajax({
                type: "get",
                url: "{:url('api/Dictionary/change')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'id': id, 'status': status},
                success: function (msg) {
                    if (msg.code == 200) {
                        $(obj).parents("tr").find(".td-manage").prepend('<a class="btn table-btn" onClick="admin_stop(this)" href="javascript:;" title="禁用"><i class="fa fa-ban"></i></a>');
                        $(obj).parents("tr").find(".td-status").html('已激活').attr("status", 1);
                        ;
                        $(obj).parents("tr").find(".td-status").addClass("enable").removeClass("disable");
                        $(obj).remove();
                        layer.msg('已激活!', {icon: 1, time: 1000});
                    }
                    if (msg.code == 1000) {
                        layer.msg('启用激活!', {icon: 1, time: 1000});
                    }
                }
            });
        });
    }

    /*右侧禁用*/
    function system_stop(obj) {
        layer.confirm('确认要禁用吗？', function (index) {
            var status = 2;
            id = $(obj).parents("tr").attr("id");
            $.ajax({
                type: "get",
                url: "{:url('api/Dictionary/change')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'id': id, 'status': status},
                success: function (msg) {
                    if (msg.code == 200) {
                        $(obj).parents("tr").find(".td-manage").prepend('<a class="btn table-btn" onClick="admin_start(this)" href="#"><i class="fa fa-check-circle-o enable" title="激活"></i></a>');
                        $(obj).parents("tr").find(".td-status").html('已禁用').attr("status", 2);
                        $(obj).parents("tr").find(".td-status").addClass("disable").removeClass("enable");
                        $(obj).remove();
                        layer.msg('已禁用!', {icon: 1, time: 1000});
                    }
                    if (msg.code == 1000) {
                        layer.msg('禁用失败!', {icon: 1, time: 1000});
                    }
                }
            });
        });
    }


    /*删除*/
    function syetem_del(obj) {
        var id = $(obj).parents("tr").attr("id");
        status = 0;
        pid = $(obj).parents("tr").attr("pid");
        pages_num = $(".table").attr("pages");
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: "get",
                url: "{:url('api/Dictionary/batch_del')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'id': id, 'status': status},
                success: function (msg) {
                    if (msg.code == 200) {
                        $(obj).parents("tr").remove();
                        // system_list(pid,pages_num);
                        layer.msg('已删除!', {icon: 1, time: 1000});
                    }
                    if (msg.code == 1000) {
                        layer.msg('删除失败!', {icon: 5, time: 1000});
                    }
                }
            });

        });
    }


</script>
</body>
</html>
